#ifndef STR_H_
#define STR_H_

#ifndef WINC_H_
#   include "winc.h"
#endif


class   WStr
    {
    wchar_t*    String;
    size_t      Size;
    size_t      Length;
    void        Init(size_t Size=0, const wchar_t* Other=0, size_t CopyLen=0);
    void        Shrink(void);
public:
    WStr(size_t Size = 0);
    WStr(const WStr&);
    WStr(const wchar_t*, size_t Len=0);
    WStr& operator=(const WStr&);
    WStr& operator=(const wchar_t*);
    wchar_t*    WChar()     { return String;        }
    size_t      Len()       { return Length;        }
    wchar_t*    Sentinel()  { return String + Size; }
   ~WStr();
    WStr& ExpandEnvVars();
    static WStr* FromProfile(const wchar_t* Section, const wchar_t* Name, const wchar_t* Path);
    static WStr* FromXml8(const char* Start, const char* End);
    static WStr* UrlFromPath(const wchar_t* Path);
    static WStr* FromTempFile();
    static WStr* Quoted(const wchar_t* Path);
    int         IsNull() { return Length == 0; }
    WStr*       Append(WStr* Str) { return Append(Str->String);   }
    WStr*       ForceTrailingSlash(wchar_t Slash=L'/');
    WStr*       Append(const wchar_t* Str);
    WStr*       TrimDir();
    HRESULT     UrlCanonicalize(WStr* Input, DWORD Flags);
    };

int         StrHasScheme(const wchar_t* Str);


#if 0
/* TStr - simple Unicode string structure.
 *
 * Make my own string functions because I'm building a really
 * small .exe and won't load any runtime libraries. I expose the
 * structure and trust myself to rarely modify it outside of StrXxx()
 * functions.
 */
typedef struct  TStr
    {
    wchar_t*    String;     /* pointer to buffer        */
    size_t      Size;       /* physical size of buffer  */
    size_t      Length;     /* logical length of string */
    }           TStr;

TStr*       StrNew(size_t size);
TStr*       StrClone(const wchar_t* Str);
int         StrIsNull(TStr* Str);
void        StrDelete(TStr* Str);
TStr*       StrAppend(TStr* Str, const wchar_t* Suffix, size_t SuffixLen);
TStr*       StrSaveSpace(TStr* Str);
TStr*       StrTempFile(void);
TStr*       StrReadFile(HANDLE Handle);
TStr*       StrUrlFromPath(const wchar_t* Path);
TStr*       StrForceTrailingSlash(TStr* Str);
TStr*       StrFromXml8(const char* Start, const char* End);
TStr*       StrFromEnv(const wchar_t* EnvStr);
TStr*       StrCanonicalize(const wchar_t* Input);
#endif

#endif  /* STR_H_ */
